// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_HR_TRAVEL_APPLICATION
// * CreateDate    : 2011/11/8 21:33:17
// * Creater       : CodeSmith
// * LastChangeDate: 2011/11/8 21:33:17
// * LastChanger   : 2011/11/8 21:33:17
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;
using ESOL.Common;
using ESOL.Business.Mst;

namespace ESOL.Business.Hr
{
/// <summary>
    /// HrTravelApplication
    /// </summary>
    public partial class HrTravelApplicationBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objHrTravelApplicationEntity">Entity</param>
        /// <returns>Entity</returns>
        public static HrTravelApplicationEntity GetHrTravelApplication(HrTravelApplicationEntity objHrTravelApplicationEntity)
        {
            return DataAccess.SelectSingle<HrTravelApplicationEntity>(objHrTravelApplicationEntity);
        }
        public static DataTable GetByCondition(string condition, string orderBy, string rowCount)
        {
            string sql = CommonFunctions.GetSelect(rowCount) + @"TA.*, P.NAME_CN AS PERSON_NAME, D.DEPARTMENT_NAME
                                FROM HR_TRAVEL_APPLICATION TA
                                LEFT JOIN MST_PERSON P ON P.PERSON_ID = TA.PERSON_ID
                                LEFT JOIN MST_DEPARTMENT D ON D.DEPARTMENT_ID = TA.DEPARTMENT_ID
                                WHERE 1=1 ";
            if (string.IsNullOrEmpty(condition) == false)
            {
                sql += condition;
            }
            if (string.IsNullOrEmpty(orderBy) == false)
            {
                sql += " ORDER BY " + orderBy;
            }
            DataSet ds = DataAccess.SelectDataSet(sql);
            if (ds != null && ds.Tables.Count > 0)
            {
                return ds.Tables[0];
            }
            return null;
        }
        public static HrTravelApplicationEntity GetById(string appId)
        {
            if (string.IsNullOrEmpty(appId))
            {
                return null;
            }
            HrTravelApplicationEntity entity = new HrTravelApplicationEntity();
            entity.ApplicationId = appId;
            return DataAccess.SelectSingle<HrTravelApplicationEntity>(entity);
        }
        public static DataSet GetTravelApplicationForSalary(string salaryMonth, string personId)
        {
            if (string.IsNullOrEmpty(salaryMonth) || string.IsNullOrEmpty(personId))
            {
                return null;
            }
            if (salaryMonth.Length == 6)
            {
                salaryMonth = salaryMonth.Substring(0, 4) + "-" + salaryMonth.Substring(4);
            }
            string sql = @"SELECT * FROM dbo.HR_TRAVEL_APPLICATION WHERE PERSON_ID = '" + personId + @"' 
                            AND (CONVERT(NVARCHAR(10),START_DATE,120) LIKE '%" + salaryMonth + @"%' OR CONVERT(NVARCHAR(10),END_DATE,120) LIKE '%" + salaryMonth + @"%')
                            AND STATUS = 'STATUS03'";
            return DataAccess.SelectDataSet(sql);
        }
        #endregion

        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objHrTravelApplicationEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertHrTravelApplication(HrTravelApplicationEntity objHrTravelApplicationEntity)
        {
            //return DataAccess.Insert(objHrTravelApplicationEntity);
            using (DataAccessBroker broker = DataAccessFactory.Instance())
            {
                try
                {
                    broker.BeginTransaction();
                    string code = "";
                    if (MstCodeRuleBs.GetCurrentOrderCode("TravelApplication", out code, broker) == false)
                    {
                        broker.RollBack();
                        return false;
                    }
                    objHrTravelApplicationEntity.TravelCode = code;
                    DataAccess.Insert(objHrTravelApplicationEntity, broker);

                    broker.Commit();
                    return true;
                }
                catch (Exception ex)
                {
                    broker.RollBack();
                    throw ex;
                }
            }
        }

        public static bool InsertHrTravelApplication(List<HrTravelApplicationEntity> objHrTravelApplicationEntityList)
        {
            return DataAccess.Insert(objHrTravelApplicationEntityList);
        }
        #endregion

        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objHrTravelApplicationEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateHrTravelApplication(HrTravelApplicationEntity objHrTravelApplicationEntity)
        {
            return DataAccess.Update(objHrTravelApplicationEntity);
        }

        public static bool UpdateHrTravelApplication(List<HrTravelApplicationEntity> objHrTravelApplicationEntityList)
        {
            return DataAccess.Update<HrTravelApplicationEntity>(objHrTravelApplicationEntityList);
        }
        #endregion

        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objHrTravelApplicationEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteHrTravelApplication(HrTravelApplicationEntity objHrTravelApplicationEntity)
        {
            return DataAccess.Delete(objHrTravelApplicationEntity);
        }

        public static bool DeleteHrTravelApplication(List<HrTravelApplicationEntity> objHrTravelApplicationEntityList)
        {
            return DataAccess.Delete<HrTravelApplicationEntity>(objHrTravelApplicationEntityList);
        }
        #endregion

        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetHrTravelApplicationAll()
        {
            return DataAccess.SelectAllDataSet<HrTravelApplicationEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<HrTravelApplicationEntity> GetHrTravelApplicationAllList()
        {
            return DataAccess.SelectAll<HrTravelApplicationEntity>();
        }
        #endregion
	}
	
	
}	

